#pragma once
#include <glm/gtx/euler_angles.hpp>
#include <cstdlib>
#include "particle_system.hpp"

class particle_shooter : public shader {
private:
	point _pos;
	glm::vec4 _basedir;
	int _color;
	float _anglevariance;
	float _speedvariance;

private:
	float
	randvalue() {
		return rand() % 1000 / 1000.0f;
	}

public:
	particle_shooter(point pos, vector dir, int color, float anglevariance, float speedvariance)
		: _pos(pos.x, pos.y, pos.z)
		, _basedir(dir.x, dir.y, dir.z, 1.0f)
		, _color(color)
		, _anglevariance(glm::radians(anglevariance))
		, _speedvariance(speedvariance) {
	}

	void
	addparticles(particle_system &sys, float curtime, int count) {
		glm::mat4 rotatemat = glm::eulerAngleXYZ((randvalue()-0.5f)*_anglevariance, (randvalue()-0.5f)*_anglevariance, (randvalue()-0.5f)*_anglevariance);
		glm::vec4 dir = rotatemat * _basedir;
		float speed = 1.0f + randvalue() * _speedvariance;

		vector v(dir.x * speed, dir.y * speed, dir.z * speed);

		for (int i = 0; i < count; i++) {
			sys.addparticle(_pos, _color, v, curtime);
		}
	}
};
